var _oFieldXmlDoc = CreateXmlDocument();
var _oFieldXslDoc = CreateXmlDocument(true);
var _oFieldXslt = CreateXslTemplate();

var _sSortColumnName = "cn";
var _bSortOrderAscend = true;

var _oLastGridColumnOver = null;

function BuildFieldList()
{
_oFieldXslDoc.load("/Tools/ImportWizard/fields.xsl");
_oFieldXslt.stylesheet = _oFieldXslDoc;
_oFieldXmlDoc.loadXML(GetFieldsXml());
UpdateFieldList();
}
function UpdateFieldList()
{


var aCells = tblGridBar.cells;
for (var i = 0; i < aCells.length; i++)
{
var oCell = aCells[i];
if (oCell.className == "gridheader")
{
var oImg = oCell.firstChild.children[0];
with (oImg.style)
{
visibility	= _sSortColumnName == oCell.field ? "visible" : "hidden";
filter		= _bSortOrderAscend ? "" : "flipv()";
oImg.alt	= _sSortColumnName == oCell.field ? (_bSortOrderAscend ? LOCID_ALT_COLUMNSORTORDER_UP:LOCID_ALT_COLUMNSORTORDER_DOWN ) : "";
}
if ( LOCID_UI_DIR=="RTL" )
{
if ( oImg.style.filter == "" )
oImg.style.filter = "fliph()" ;
else
oImg.style.filter += " fliph()" ;
}
}
}


var oFieldXslProc = _oFieldXslt.createProcessor();
oFieldXslProc.input = _oFieldXmlDoc;
oFieldXslProc.addParameter("sortColumnName", _sSortColumnName);
oFieldXslProc.addParameter("sortLanguage", XML_LANGUAGE_NAME);
oFieldXslProc.addParameter("sortOrder", _bSortOrderAscend ? "ascending" : "descending");
oFieldXslProc.addParameter("RTL", LOCID_UI_DIR=="RTL" ? "true" : "false");
oFieldXslProc.transform();
FieldList.innerHTML = oFieldXslProc.output;


}

function onGridColumnClick()
{
var o = event.srcElement;

switch (o.tagName)
{
case "IMG": return;
case "NOBR": o = o.parentElement;
}


if (o.className == "gridheader")
{
if (o.field == _sSortColumnName)
{
_bSortOrderAscend = !_bSortOrderAscend;
}
else
{
_sSortColumnName = o.field;
_bSortOrderAscend = true;
}
}


UpdateFieldList();
}

function onGridColumnMouseOver()
{
var o = event.srcElement;

switch (o.tagName)
{
case "IMG": return;
case "NOBR": o = o.parentElement;
}


if (o.className == "gridheader" && o.runtimeStyle.backgroundImage != "url(/_imgs/grid/grid_BarBkOn.gif)")
{
o.runtimeStyle.backgroundImage = "url(/_imgs/grid/grid_BarBkOn.gif)";
_oLastGridColumnOver = o;
}
}


function onGridColumnMouseOut()
{
var o = event.toElement;


if (!IsNull(_oLastGridColumnOver) && !(!IsNull(o) && (o == _oLastGridColumnOver || o.parentElement == _oLastGridColumnOver || o.parentElement.parentElement == _oLastGridColumnOver)))
{
_oLastGridColumnOver.runtimeStyle.backgroundImage = "";
_oLastGridColumnOver = null;
}
}
function on()
{
_oLastGlow = event.srcElement;
while (_oLastGlow.tagName !=  "TR" )
{
_oLastGlow = _oLastGlow.parentElement;
_oLastGlow.title = _oLastGlow.innerText;
}
_oLastGlow.runtimeStyle.backgroundColor = "#c4ddff";
}
function off()
{
if (_oLastGlow)	_oLastGlow.runtimeStyle.backgroundColor = "";
}

